package com.neu.wms.controller;

import com.neu.wms.dto.PersmissionDto;
import com.neu.wms.service.PermissionService;
import com.neu.wms.util.ResultVo;
import com.neu.wms.vo.TreeNodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DAIJUNQIANG
 * @version 1.0
 * @description 关于权限的控制类
 * @date 2023/7/8 19:17
 */
@RestController
@RequestMapping("/permissions")
public class PermissionController {

	@Autowired
	private PermissionService permissionService;
	@GetMapping("{rid}")
	public ResultVo queryByRid(@PathVariable Integer rid){
		List<TreeNodeVo> treeNodeVos = permissionService.selectAll(0);
		Integer[] defaultChecked = permissionService.selectByRid(rid);
		return ResultVo.ok().data("treeNodes",treeNodeVos).data("defaultChecked",defaultChecked);
	}
	@PostMapping("")
	public ResultVo updatePermissionByRid(@RequestBody PersmissionDto persmissionDto){
		permissionService.updatePermissionByRid(persmissionDto);
		return ResultVo.ok("授权成功");
	}
}
